Create an InlineKeyboardButton with specific columns using the method below.
public static IReplyMarkup CreateInlineKeyboardButton(Dictionary<string, string> buttonList, int columns) { int rows = (int)Math.Ceiling((double)buttonList.Count / (double)columns); InlineKeyboardButton[][] buttons = new InlineKeyboardButton[rows][]; for (int i = 0; i < buttons.Length; i++) { buttons[i] = buttonList .Skip(i * columns) .Take(columns) .Select(direction => new InlineKeyboardCallbackButton( direction.Key, direction.Value ) as InlineKeyboardCallbackButton) .ToArray(); } return new InlineKeyboardMarkup(buttons); }
Use the method as follows:
public static IReplyMarkup CreateInLineMainMenuMarkup() { Dictionary<string, string> buttonsList = new Dictionary<string, string>(); buttonsList.Add("one", "DATA1"); buttonsList.Add("two", "DATA2"); buttonsList.Add("three", "DATA3"); return CreateInlineKeyboardButton(buttonsList, 2); }
Thanks pouladpld for creating this feature.
Majid gharaei
source share